package com.cgy.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * MessageService
 *
 * @author think
 * @since 2023/11/2
 */
@Slf4j
@Service
public class MessageServiceImpl implements IMessageService {

    @Resource
    private RabbitTemplate rabbitTemplate;

    @Override
    public void sendMessage(String exchange, String routingKey, Object msg) {
        // 消息发送失败返回到队列中, yml需要配置 publisher-returns: true
        rabbitTemplate.setMandatory(true);
        // 发送消息
        rabbitTemplate.convertAndSend(exchange, routingKey, msg);
    }

}